{% extends 'layout.html' %}

{% block content %}
<div class="container">
    <div class="row">
        <div class="col-md-3">
            <div class="list-group">
                <a href="{% url 'goods_list' %}" class="list-group-item list-group-item-action {% if not category_id %}active{% endif %}">
                    全部商品
                </a>
                {% for cag in categories %}
                <a href="{% url 'goods_list' %}?category={{ cag.id }}" class="list-group-item list-group-item-action {% if category_id == cag.id|stringformat:'i' %}active{% endif %}">
                    {{ cag.cag_name }}
                </a>
                {% endfor %}
            </div>
        </div>
        <div class="col-md-9">
            <div class="row">
                {% for good in goods %}
                <div class="col-md-4 mb-4">
                    <div class="card h-100">
                        <img src="{{ good.goods_img.url }}" class="card-img-top" alt="{{ good.goods_name }}">
                        <div class="card-body">
                            <h5 class="card-title">{{ good.goods_name }}</h5>
                            <p class="card-text">价格: ¥{{ good.goods_price }}</p>
                            <p class="card-text">库存: {{ good.goods_quantity }}</p>
                            <a href="{% url 'goods_detail' good.id %}" class="btn btn-primary">查看详情</a>
                            <a href="/cart/add_cart/?id={{good.id}}&quantity=1" class="btn btn-success ml-2">加入购物车</a>
                        </div>
                    </div>
                </div>
                {% endfor %}
            </div>
        </div>
    </div>
</div>
{% endblock %}